/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GiveTakeStrategyComponent.java
 *
 * Created on 11/Dez/2011, 11:25:38
 */

package intopo.game.impl.givetake;

import intopo.game.gui.AbstractStrategyEditorComponent;
import java.awt.CardLayout;

/**
 *
 * @author pedro
 */
public class GiveTakeStrategyComponent
	extends AbstractStrategyEditorComponent<GiveTakeStrategy>
{
	private enum Type {
		deterministic,
		probabilistic;
	}
	/** Creates new form BeanForm */
	public GiveTakeStrategyComponent ()
	{
		initComponents();
	}
	@Override
	public String getConfigFileDescription ()
	{
		throw new UnsupportedOperationException ("Not supported yet.");
	}

	@Override
	public GiveTakeStrategy getStrategy ()
	{
		String type = (String) this.typeComboBox.getSelectedItem ();
		if (type.equals ("deterministic")) {
			int tg = (Integer) this.giveTimeDetFormattedTextField.getValue ();
			int tt = (Integer) this.takeTimeDetFormattedTextField.getValue ();
			return new GiveTakeDeterministicStrategy (tg, tt);
		}
		else if (type.equals ("probabilistic")) {
			int ng = (Integer) this.noneGTimeFormattedTextField.getValue ();
			float gp = (Float) this.giveProbabilityFormattedTextField.getValue ();
			int tg = (Integer) this.giveTimeProFormattedTextField.getValue ();
			int nt = (Integer) this.noneTTimeFormattedTextField.getValue ();
			float tp = (Float) this.takeProbabilityFormattedTextField.getValue ();
			int tt = (Integer) this.takeTimeProFormattedTextField.getValue ();
			return new GiveTakeProbabilisticStrategy (ng, gp, tg, nt, tp, tt);
		}
		else {
			throw new Error ("Unreachable statement in GiveTakeStrategyComponent.getStrategy()");
		}
	}

	@Override
	public void setStrategy (GiveTakeStrategy strategy)
	{
		if (strategy instanceof GiveTakeProbabilisticStrategy) {
			GiveTakeProbabilisticStrategy s = (GiveTakeProbabilisticStrategy) strategy;
			this.typeComboBox.setSelectedIndex (1);
			this.noneGTimeFormattedTextField.setValue (new Integer (s.noneGiterations));
			this.giveProbabilityFormattedTextField.setValue (new Float (s.giveProbability));
			this.giveTimeProFormattedTextField.setValue (new Integer (s.giveIteration));
			this.noneTTimeFormattedTextField.setValue (new Integer (s.noneTiterations));
			this.takeProbabilityFormattedTextField.setValue (new Float (s.takeProbability));
			this.takeTimeProFormattedTextField.setValue (new Integer (s.takeIteration));
		}
		else if (strategy instanceof GiveTakeDeterministicStrategy) {
			GiveTakeDeterministicStrategy s = (GiveTakeDeterministicStrategy) strategy;
			this.typeComboBox.setSelectedIndex (0);
			this.giveTimeDetFormattedTextField.setValue (new Integer (s.giveTime));
			this.takeTimeDetFormattedTextField.setValue (new Integer (s.takeTime));
		}
		else {
			throw new UnsupportedOperationException ("Not supported yet: " + strategy.getClass ());
		}
		this.strategy = strategy;
		CardLayout layout = (CardLayout) this.strategiesPanel.getLayout ();
		String type = (String) this.typeComboBox.getSelectedItem ();
		layout.show (this.strategiesPanel, type);
	}

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
   // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
   private void initComponents() {
      java.awt.GridBagConstraints gridBagConstraints;

      strategiesPanel = new javax.swing.JPanel();
      deterministicPanel = new javax.swing.JPanel();
      javax.swing.JLabel jLabel1 = new javax.swing.JLabel();
      giveTimeDetFormattedTextField = new javax.swing.JFormattedTextField();
      javax.swing.JLabel jLabel2 = new javax.swing.JLabel();
      takeTimeDetFormattedTextField = new javax.swing.JFormattedTextField();
      probabilisticPanel = new javax.swing.JPanel();
      javax.swing.JLabel jLabel5 = new javax.swing.JLabel();
      noneGTimeFormattedTextField = new javax.swing.JFormattedTextField();
      javax.swing.JLabel jLabel6 = new javax.swing.JLabel();
      giveProbabilityFormattedTextField = new javax.swing.JFormattedTextField();
      javax.swing.JLabel jLabel3 = new javax.swing.JLabel();
      giveTimeProFormattedTextField = new javax.swing.JFormattedTextField();
      javax.swing.JLabel jLabel7 = new javax.swing.JLabel();
      noneTTimeFormattedTextField = new javax.swing.JFormattedTextField();
      javax.swing.JLabel jLabel8 = new javax.swing.JLabel();
      takeProbabilityFormattedTextField = new javax.swing.JFormattedTextField();
      javax.swing.JLabel jLabel4 = new javax.swing.JLabel();
      takeTimeProFormattedTextField = new javax.swing.JFormattedTextField();
      javax.swing.JPanel typePanel = new javax.swing.JPanel();
      jLabel9 = new javax.swing.JLabel();
      typeComboBox = new javax.swing.JComboBox (Type.values ());

      setLayout(new java.awt.BorderLayout());

      strategiesPanel.setLayout(new java.awt.CardLayout());

      deterministicPanel.setLayout(new java.awt.GridBagLayout());

      jLabel1.setText("time to give: ");
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 0;
      deterministicPanel.add(jLabel1, gridBagConstraints);

      giveTimeDetFormattedTextField.setColumns(5);
      giveTimeDetFormattedTextField.setValue(new Integer (1));
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 1;
      deterministicPanel.add(giveTimeDetFormattedTextField, gridBagConstraints);

      jLabel2.setText("time to take: ");
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 0;
      deterministicPanel.add(jLabel2, gridBagConstraints);

      takeTimeDetFormattedTextField.setColumns(5);
      takeTimeDetFormattedTextField.setValue(new Integer (2));
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 1;
      deterministicPanel.add(takeTimeDetFormattedTextField, gridBagConstraints);

      strategiesPanel.add(deterministicPanel, "deterministic");

      probabilisticPanel.setLayout(new java.awt.GridBagLayout());

      jLabel5.setText("time with resource: ");
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 0;
      gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
      probabilisticPanel.add(jLabel5, gridBagConstraints);

      noneGTimeFormattedTextField.setColumns(5);
      noneGTimeFormattedTextField.setValue(new Integer (1));
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 1;
      probabilisticPanel.add(noneGTimeFormattedTextField, gridBagConstraints);

      jLabel6.setText("give probability: ");
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 0;
      gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
      probabilisticPanel.add(jLabel6, gridBagConstraints);

      giveProbabilityFormattedTextField.setColumns(5);
      giveProbabilityFormattedTextField.setValue(new Float (0.5));
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 1;
      probabilisticPanel.add(giveProbabilityFormattedTextField, gridBagConstraints);

      jLabel3.setText("time to give: ");
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 0;
      gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
      probabilisticPanel.add(jLabel3, gridBagConstraints);

      giveTimeProFormattedTextField.setColumns(5);
      giveTimeProFormattedTextField.setValue(new Integer (3));
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 1;
      probabilisticPanel.add(giveTimeProFormattedTextField, gridBagConstraints);

      jLabel7.setText("time without resource: ");
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 0;
      gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
      probabilisticPanel.add(jLabel7, gridBagConstraints);

      noneTTimeFormattedTextField.setColumns(5);
      noneTTimeFormattedTextField.setValue(new Integer (2));
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 1;
      probabilisticPanel.add(noneTTimeFormattedTextField, gridBagConstraints);

      jLabel8.setText("take probability: ");
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 0;
      gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
      probabilisticPanel.add(jLabel8, gridBagConstraints);

      takeProbabilityFormattedTextField.setColumns(5);
      takeProbabilityFormattedTextField.setValue(new Float (0.5));
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 1;
      probabilisticPanel.add(takeProbabilityFormattedTextField, gridBagConstraints);

      jLabel4.setText("time to take: ");
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 0;
      gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
      probabilisticPanel.add(jLabel4, gridBagConstraints);

      takeTimeProFormattedTextField.setColumns(5);
      takeTimeProFormattedTextField.setValue(new Integer (4));
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 1;
      probabilisticPanel.add(takeTimeProFormattedTextField, gridBagConstraints);

      strategiesPanel.add(probabilisticPanel, "probabilistic");

      add(strategiesPanel, java.awt.BorderLayout.CENTER);

      jLabel9.setText("type: ");
      typePanel.add(jLabel9);

      typeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "deterministic", "probabilistic" }));
      typeComboBox.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            typeComboBoxActionPerformed(evt);
         }
      });
      typePanel.add(typeComboBox);

      add(typePanel, java.awt.BorderLayout.NORTH);
   }// </editor-fold>//GEN-END:initComponents

	 private void typeComboBoxActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_typeComboBoxActionPerformed
		CardLayout layout = (CardLayout) this.strategiesPanel.getLayout ();
		String type = (String) this.typeComboBox.getSelectedItem ();
		layout.show (this.strategiesPanel, type);
	 }//GEN-LAST:event_typeComboBoxActionPerformed

   // Variables declaration - do not modify//GEN-BEGIN:variables
   private javax.swing.JPanel deterministicPanel;
   private javax.swing.JFormattedTextField giveProbabilityFormattedTextField;
   private javax.swing.JFormattedTextField giveTimeDetFormattedTextField;
   private javax.swing.JFormattedTextField giveTimeProFormattedTextField;
   private javax.swing.JLabel jLabel9;
   private javax.swing.JFormattedTextField noneGTimeFormattedTextField;
   private javax.swing.JFormattedTextField noneTTimeFormattedTextField;
   private javax.swing.JPanel probabilisticPanel;
   private javax.swing.JPanel strategiesPanel;
   private javax.swing.JFormattedTextField takeProbabilityFormattedTextField;
   private javax.swing.JFormattedTextField takeTimeDetFormattedTextField;
   private javax.swing.JFormattedTextField takeTimeProFormattedTextField;
   private javax.swing.JComboBox typeComboBox;
   // End of variables declaration//GEN-END:variables

}
